#include "safewidget.h"
#include "common/safescanbottom.h"
#include "../commom/wenlibackwidget.h"
#include "../commom/stackstatuswidget.h"
#include <QIcon>
#include <QPropertyAnimation>
#include <QVBoxLayout>
#include <src/sqltest/serialport.h>
SafeWidget::SafeWidget(QWidget *parent) :
    ShadowWidget(parent)
{
    this->initUI();
    this->initConnect();

}

void SafeWidget::initUI()
{
    this->setFixedSize(900, 600);
    this->setWindowIcon(QIcon(":/main/Logo"));
    this->setWindowTitle(tr("测试"));
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
    m_topBackWidget = new WenliBackWidget;
    m_stackStatusWidget = new StackStatusWidget;
    m_topBackWidget->insertWidget(m_stackStatusWidget);
    m_topBackWidget->setButtonInfo(":/safe/return");
    m_stackStatusWidget->setStaticIcon(":/safe/logo_normal");
    m_stackStatusWidget->setNormalButton(":/safe/start");
    m_stackStatusWidget->setTextInfo("奥瑞", "内部测试");
    m_topBackWidget->setFixedHeight(150);//绿条的宽度
    m_topBackWidget->m_button->hide();//返回键给隐藏起来
    m_stackWidget = new QStackedWidget(this);//打开后的页面大小
    m_stackWidget->setGeometry(rect());
    m_stackWidget->lower();
    m_axisData = new axisData;
    m_stackWidget->addWidget(m_axisData);
    m_youhuaWidget = new YouhuaWidget;
    m_cleanWidget = new CleanWidget;

//    m_serialSet = new serialSet;
    m_stackWidget->addWidget(m_cleanWidget);
    m_scanBottomWidget = new SafeScanBottom;
    m_sqliteTest = new sqliteTest;
    m_stackWidget->addWidget(m_sqliteTest);
    QPropertyAnimation *m_upMainAnimation = new QPropertyAnimation(m_topBackWidget, "pos");
    m_upMainAnimation->setDuration(200);
    m_upMainAnimation->setStartValue(QPoint(0, 0));//上部分开始收缩的起点
    m_upMainAnimation->setEndValue(QPoint(0, -150));//上部分收缩的结点

    QPropertyAnimation *m_downMainAnimation = new QPropertyAnimation(m_scanBottomWidget, "pos");
    m_downMainAnimation->setDuration(200);
    m_downMainAnimation->setStartValue(QPoint(0, 150));//下部分开始收缩的起点
    m_downMainAnimation->setEndValue(QPoint(0, 600));//下部分收缩的结点

    QPropertyAnimation *m_upGarAnimation = new QPropertyAnimation(m_topBackWidget, "pos");
    m_upGarAnimation->setDuration(200);
    m_upGarAnimation->setStartValue(QPoint(0, -150));
    m_upGarAnimation->setEndValue(QPoint(0, 0));

    QPropertyAnimation *m_downGarAnimation = new QPropertyAnimation(m_scanBottomWidget, "pos");
    m_downGarAnimation->setDuration(200);
    m_downGarAnimation->setStartValue(QPoint(0, 600));
    m_downGarAnimation->setEndValue(QPoint(0, 150));//界面返回时回弹的高度

    m_downGroup = new QParallelAnimationGroup;
    m_downGroup->addAnimation(m_upGarAnimation);
    m_downGroup->addAnimation(m_downGarAnimation);


    m_upGroup = new QParallelAnimationGroup;
    m_upGroup->addAnimation(m_upMainAnimation);
    m_upGroup->addAnimation(m_downMainAnimation);

    QVBoxLayout *vLayout = new QVBoxLayout;
    vLayout->addWidget(m_topBackWidget);
    vLayout->addWidget(m_scanBottomWidget);
    vLayout->setSpacing(0);
    vLayout->setContentsMargins(0,0,0,0);

    this->setLayout(vLayout);

}

void SafeWidget::initConnect()
{
    connect(m_scanBottomWidget, SIGNAL(axisClicked()), this, SLOT(goToTest()));
    connect(m_scanBottomWidget, SIGNAL(youhuaClicked()), this, SLOT(goToYouhua()));
//    connect(m_scanBottomWidget, SIGNAL(cleanClicked()), this, SLOT(goToClean()));
    connect(m_cleanWidget, SIGNAL(goToMain()), this, SLOT(goToMained()));
    connect(m_youhuaWidget, SIGNAL(goToMain()), this, SLOT(goToMained()));

    connect(m_topBackWidget, SIGNAL(buttonClicked()), this, SIGNAL(goToMain()));
    connect(m_topBackWidget, SIGNAL(showMin()), this, SLOT(showMinimized()));
    connect(m_topBackWidget, SIGNAL(closeWidget()), this, SLOT(closeWidget()));
    connect(m_sqliteTest, SIGNAL(showMin()), this, SLOT(showMinimized()));
    connect(m_sqliteTest, SIGNAL(goToMain()), this, SLOT(goToMained()));
    connect(m_sqliteTest, SIGNAL(closeWidget()), this, SLOT(closeWidget()));
    connect(m_axisData, SIGNAL(closeWidget()), this, SLOT(closeWidget()));
    connect(m_axisData, SIGNAL(showMin()), this, SLOT(showMinimized()));
    connect(m_axisData, SIGNAL(goToMain()), this, SLOT(goToMained()));


}
void SafeWidget::goToMained()
{
//    m_grayWidget->show();
    m_downGroup->start();
}

void SafeWidget::goToClean()
{
    m_stackWidget->setCurrentIndex(1);
    m_upGroup->start();
    m_cleanWidget->startFirst();//页面打开动画
}

void SafeWidget::goToYouhua()
{
    m_stackWidget->setCurrentIndex(2);
    m_upGroup->start();
    m_cleanWidget->startFirst();//页面打开动画

}

void SafeWidget::goToTest()
{
    m_stackWidget->setCurrentIndex(0);
    m_upGroup->start();
    m_cleanWidget->startFirst();//页面打开动画

}
void SafeWidget::closeWidget()
{
    qApp->quit();
}
